package cn.xm.org.controller;


import cn.xm.basic.anno.LogAnno;
import cn.xm.basic.util.AjaxResult;
import cn.xm.basic.util.PageList;
import cn.xm.org.domain.SystemDictionaryType;
import cn.xm.org.query.SystemDictionaryTypeQuery;
import cn.xm.org.service.SystemDictionaryTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictype")
@Api(value = "部门的API",description="部门相关的CRUD功能")
public class SystemDictionaryTypeController {

    @Autowired
    private SystemDictionaryTypeService systemDictionaryTypeService;

    @PutMapping
    @ApiOperation(value = "增加或修改部门" )
    public AjaxResult addOrUpdate(@ApiParam(value="部门实体类",required = true) @RequestBody SystemDictionaryType systemDictionaryType) {
        if (systemDictionaryType.getId() == null) {
            systemDictionaryTypeService.add(systemDictionaryType);
        } else {
            systemDictionaryTypeService.update(systemDictionaryType);
        }
        return AjaxResult.me().success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "通过ID删除" )
    public AjaxResult delete(@ApiParam(value="ID属性",required = true) @PathVariable("id") Long id) {
        systemDictionaryTypeService.delete(id);
        return AjaxResult.me().success();
    }

    @PatchMapping
    @ApiOperation(value = "批量删除" )
    public AjaxResult batchDelete(@RequestBody List<Long> ids) {
        systemDictionaryTypeService.batchDelete(ids);
        return AjaxResult.me().success();
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    public SystemDictionaryType findById(@ApiParam(value="ID属性",required = true) @PathVariable("id") Long id) {
        SystemDictionaryType systemDictionaryType = systemDictionaryTypeService.findById(id);
        return systemDictionaryType;
    }

    @GetMapping
    @ApiOperation(value = "查询所有" )
    public List<SystemDictionaryType> findAll() {
        return systemDictionaryTypeService.findAll();
    }

    @PostMapping
    @ApiOperation(value = "分页查询" )
    @LogAnno(method = "queryByPage",methodDes = "分页查询")
    public PageList<SystemDictionaryType> queryByPage(@ApiParam(value="分页条件封装的类",required = true) @RequestBody SystemDictionaryTypeQuery systemDictionaryTypeQuery) {
        return systemDictionaryTypeService.queryByPage(systemDictionaryTypeQuery);
    }
}
